package com.itheima;

import java.util.Scanner;

/**
 * 2025/3/22 10:21
 * 案例-健康计算器（要求使用今天学习的知识）
 */

public class HealthCalculate {

    public static void main(String[] args) {
        //创建Scanner对象
        Scanner sc = new Scanner(System.in);
        //1. 提示用户依次输入用户信息：性别、年龄、身高、体重
        System.out.println("请输入您的性别：（0女  1男）");
        //获取用户输入的性别
        int gender = sc.nextInt();
        System.out.println("请输入您的年龄：");
        int age = sc.nextInt();
        System.out.println("请输入您的身高(cm)：");
        double height = sc.nextDouble();
        System.out.println("请输入您的体重(kg)：");
        double weight = sc.nextDouble();

        //2. 根据用户输入的性别、年龄、身高、体重，调用计算BMI和BMR的方法，并获取结果

        double mbi = getMBI(weight, height);
        double bmr = getBMR(gender, age, height, weight);
        System.out.println("您的BMI为：" + mbi);
        System.out.println("您的BMR为：" + bmr);

        if (mbi<18.5){
            System.out.println("您属于偏瘦人群");
        } else if (mbi<=24.9) {
            System.out.println("您属于正常人群，非常棒，继续坚持。。。。。");
        } else if (mbi <= 29.9) {
            System.out.println("您属于偏胖人群");
        }else {
            System.out.println("您属于肥胖人群，注意锻炼。。。。");
        }


    }

    //计算BMI
    public static double getMBI(double weight, double height) {
        return weight / (height / 100 * height / 100);
    }

    //计算BMR
    public static double getBMR(int gender, int age, double height, double weight) {
        //三元运算符
        double bmr0 = 447.593 + (9.247 * weight) + (3.098 * height) - (4.33 * age);
        double bmr1 = 88.632 + (13.397 * weight) + (4.799 * height) - (5.677 * age);
//        a>b?a:b;
        return gender == 0 ? bmr0 : bmr1;
    }

}
